package com.whmall.service.crm.module.supplierchemical.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.whmall.common.enumeration.YesNoEnum;
import com.whmall.component.entity.dto.OperatorReqDTO;
import com.whmall.service.crm.entity.dto.supplierchemical.SupplierChemicalCraftAttachmentReqDTO;
import com.whmall.service.crm.module.supplierchemical.entity.SupplierChemicalCraftAttachmentDO;
import com.whmall.service.crm.module.supplierchemical.service.SupplierChemicalCraftAttachmentService;
import com.whmall.service.crm.module.supplierchemical.dao.SupplierChemicalCraftAttachmentMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;


@Slf4j
@Service
public class SupplierChemicalCraftAttachmentServiceImpl implements SupplierChemicalCraftAttachmentService{

    @Autowired
    private SupplierChemicalCraftAttachmentMapper mapper;

    @Override
    public void removeBatch(List<Long> idList, OperatorReqDTO operatorReqDTO) {

        if(CollUtil.isNotEmpty(idList)){
            mapper.updateBatchDel(idList, operatorReqDTO.getOperatorId());
        }
    }

    @Override
    public void saveBatch(List<String> list,Long craftId,OperatorReqDTO operatorReqDTO) {
        mapper.insertBatch(list.stream()
                .map(a -> SupplierChemicalCraftAttachmentDO
                        .builder()
                        .craftId(craftId)
                        .attachmentUrl(a)
                        .createId(operatorReqDTO.getOperatorId())
                        .createTime(new Date())
                        .build())
                .collect(Collectors.toList()));
    }
}